package com.xbts.web.controller.cloud;

import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.system.domain.CnShoppingCar;
import com.xbts.system.service.ICnShoppingCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 购物车Controller
 *
 * @author xbts
 * @date 2023-08-03
 */
@Api("购物车")
@RestController
@RequestMapping("/system/car")
public class CnShoppingCarController extends BaseController {

    @Autowired
    private ICnShoppingCarService cnShoppingCarService;

    /**
     * 查询购物车列表
     */
    @ApiOperation("查询购物车列表")
    @PreAuthorize("@ss.hasPermi('system:car:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnShoppingCar cnShoppingCar) {
        startPage(cnShoppingCar);
        List<CnShoppingCar> list = cnShoppingCarService.selectCnShoppingCarList(cnShoppingCar);
        return getDataTable(list);
    }

    /**
     * 导出购物车列表
     */
    @ApiOperation("导出购物车列表")
    @PreAuthorize("@ss.hasPermi('system:car:export')")
    @Log(title = "购物车", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody CnShoppingCar cnShoppingCar) {
        List<CnShoppingCar> list = cnShoppingCarService.selectCnShoppingCarList(cnShoppingCar);
        ExcelUtil<CnShoppingCar> util = new ExcelUtil<CnShoppingCar>(CnShoppingCar.class);
        util.exportExcel(response, list, "购物车数据");
    }

    /**
     * 获取购物车详细信息
     */
    @ApiOperation("获取购物车详细信息")
    @ApiImplicitParam(name = "shoppingCarId", value = "购物车ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('system:car:query')")
    @GetMapping(value = "/{shoppingCarId}")
    public AjaxResult getInfo(@PathVariable("shoppingCarId") String shoppingCarId) {
        return success(cnShoppingCarService.selectCnShoppingCarByShoppingCarId(shoppingCarId));
    }

    /**
     * 新增购物车
     */
    @ApiOperation("新增购物车")
    @PreAuthorize("@ss.hasPermi('system:car:add')")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnShoppingCar cnShoppingCar) {
        return toAjax(cnShoppingCarService.insertCnShoppingCar(cnShoppingCar));
    }

    /**
     * 修改购物车
     */
    @ApiOperation("修改购物车")
    @PreAuthorize("@ss.hasPermi('system:car:edit')")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CnShoppingCar cnShoppingCar) {
        return toAjax(cnShoppingCarService.updateCnShoppingCar(cnShoppingCar));
    }

    /**
     * 删除购物车
     */
    @ApiOperation("删除购物车")
    @ApiImplicitParam(name = "shoppingCarIds", value = "购物车ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('system:car:remove')")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
    @PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> shoppingCarIds) {
        return toAjax(cnShoppingCarService.deleteCnShoppingCarByShoppingCarIds(shoppingCarIds));
    }




}
